<?php

namespace Database\Seeders;

use App\Models\BankCard;
use App\Models\Comment;
use App\Models\Order;
use App\Models\OrderItem;
use App\Models\Phone;
use App\Models\Post;
use App\Models\Price;
use App\Models\Product;
use App\Models\User;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        User::factory(10)->create();

        // 没有用户跳出
        $userCount = User::query()->count();
        if ($userCount < 10) {
            return;
        }

        if (Phone::query()->count() == 0) {
            Phone::factory(10)->create(); // 创建10个手机
        }

        if (BankCard::query()->count() == 0) {
            BankCard::factory(10)->create(); // 创建10个银行卡
        }

        if (Post::query()->count() == 0) {
            Post::factory(10)->create(); // 创建10个推文
        }

        // 没有推文跳出
        $postCount = Post::query()->count();
        if ($postCount < 10) {
            return;
        }

        if (Comment::query()->count() == 0) {
            Comment::factory(10)->create(); // 创建10条推文的评论
        }

        /* 商品、价格、订单、订单商品 */
        if (Product::query()->count() == 0) {
            Product::factory(10)->create(); // 创建10条商品记录
        }

        if (Price::query()->count() == 0) {
            price::factory(10)->create(); // 创建10条商品价格记录
        }

        if (Order::query()->count() == 0) {
            Order::factory(10)->create(); // 创建10条订单记录
        }

        if (OrderItem::query()->count() == 0) {
            OrderItem::factory(10)->create(); // 创建10条订单商品记录
        }
    }
}
